package org.softmed.rest.server.core.http.specific;

import java.util.HashMap;
import java.util.Map;

import org.restlet.Context;
import org.restlet.data.Form;
import org.restlet.data.MediaType;
import org.restlet.data.Method;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.data.Status;
import org.softmed.rest.config.HttpMethod;
import org.softmed.rest.config.MimeTypeHandler;
import org.softmed.rest.config.Resource;
import org.softmed.rest.server.core.handler.HandlerProcessParameters;
import org.softmed.rest.server.core.handler.HandlerProcessor;
import org.softmed.rest.server.core.http.AbstractCommonSpecificHttpMethodProcessor;

public class PutProcessor extends AbstractCommonSpecificHttpMethodProcessor
		implements Cloneable {

	MediaType mediaTypeToProcess;

	public PutProcessor clone() {
		return new PutProcessor();

	}

	@Override
	public boolean canProcess(HttpMethod method) {
		return method.getName().equalsIgnoreCase(Method.PUT.getName());
	}

	@Override
	protected String getMimeTypeToProcess() {
		if (mediaTypeToProcess == null)
			return null;

		return mediaTypeToProcess.getName();
	}

	@Override
	protected boolean isProcessMimeTypeHandler() {
		return true;
	}

	@Override
	protected void preProcessHttpMethod(HttpMethod requestHttpMethod,
			HandlerProcessor instanceHandlerSolver,
			HandlerProcessParameters parameters) {

		// determine the media type of the content sent by the client

		mediaTypeToProcess = null;
		mediaTypeToProcess = parameters.getRequest().getEntity().getMediaType();

		if (mediaTypeToProcess != null)
			parameters.getSequenceParameters().put("mime-type",
					mediaTypeToProcess.getName());
	}

	@Override
	protected void postProcessHttpMethod(HttpMethod requestHttpMethod,
			HandlerProcessor instanceHandlerSolver,
			HandlerProcessParameters parameters) {
		// TODO Auto-generated method stub
//		parameters.getResponse().setStatus(Status.SUCCESS_ACCEPTED);
	}

	@Override
	protected void preProcessMimeType(MimeTypeHandler selectedMimeTypeHandler,
			HttpMethod requestHttpMethod,
			HandlerProcessor instanceHandlerSolver,
			HandlerProcessParameters parameters) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void postProcessMimeType(MimeTypeHandler selectedMimeTypeHandler,
			HttpMethod requestHttpMethod,
			HandlerProcessor instanceHandlerSolver,
			HandlerProcessParameters parameters) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void stopProcessingAfterHttpHandler() {
		// TODO Auto-generated method stub

	}

}
